package s03;

import base.Bean;
import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.FixedValue;

/**
 * FixedValue
 * 将所有方法的返回值都设置成返回指定的值
 *
 * @author wangpp
 */
public class FixValueTest {

    public static void main(String[] args) {
        Enhancer e = new Enhancer();
        e.setSuperclass(Bean.class);
        e.setCallback(new FixedValue() {
            @Override
            public Object loadObject() throws Exception {
                return "hello CGLIB Fix Value";
            }
        });

        Bean be = (Bean) e.create();
        System.out.println(be.test("null"));
        System.out.println(be.toString());
        System.out.println(be.getClass());
        System.out.println(be.hashCode()); //Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Number
    }
}
